<template>
  <div>
     <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!-- 搜索框 -->
      <el-input placeholder="请输入内容" style="width:30%" class="input-with-select">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!-- 订单列表 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number" width="200"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" >
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.order_pay=='1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            <!-- {{ scope.row.create_time | dateFormat('yyyy-MM-dd hh:mm:ss') }} -->
            {{ scope.row.create_time | dateFormat22('yyyy-MM-dd hh:mm:ss') }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" circle size="mini" @click="editOrder"></el-button>
            <el-button type="success" icon="el-icon-location" circle size="mini" @click="progressFn"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
      
    </el-card>  
    <!-- 修改订单弹框 -->
      <el-dialog
        title="修改地址"
        :visible.sync="editDialogVisible"
        width="50%">
        <el-form ref="form"  label-width="80px">
          <el-form-item label="省市区/县">
            <el-cascader
              v-model="selectOpt"
              :options="citydata"
              :props="{ expandTrigger: 'hover' }"
              @change="handleChange">
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址">
            <el-input></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 物流信息对话框-->
      <el-dialog
      title="物流信息"
      :visible.sync="progressDialogVisible"
      width="50%">
        <el-timeline :reverse="reverse">
          <el-timeline-item
            v-for="(activity, index) in progressList"
            :key="index"
            :timestamp="activity.time">
            {{activity.context}}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
  </div>
</template>

<script>
import citydata from './citydata'
export default {

  data () {
    return {
      queryInfo:{
        query:'',
        pagenum:1,
        pagesize:5
      },
      orderList:[],
      total:0,
      editDialogVisible:false,
      citydata,
      selectOpt:[],
      progressDialogVisible:false,
      progressList:[],
      reverse:false
    }
  },

  methods: {
    // 获取订单列表
    async getOrderList() {
      const {data:res} = await this.$http.get('orders',{
        params:this.queryInfo
      })
      if(res.meta.status == 200) {
        this.orderList = res.data.goods
        this.total = res.data.total
        console.log(this.orderList)
        console.log(this.total)
      }
    },
    // 显示多少条触发
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getOrderList()
    },
    // 改变当前页码触发
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.getOrderList()
    },
    // 编辑订单
    editOrder() {
      this.editDialogVisible = true
    },
    // 级联选择器选择的内容
    handleChange() {
      console.log(this.selectOpt)
    },
    // 物流信息
    async progressFn() {
      this.progressDialogVisible = true
      const { data:res } = await this.$http.get('/kuaidi/1106975712662')
      console.log(res)
      if(res.meta.status == 200) {
        this.progressList = res.data
      }
      console.log(this.progressList)
    }
  },

  created () {
    this.getOrderList()
  }
}
</script>

<style lang='less' scoped>

</style>
